import { requestClient } from '#/api/request';

export namespace orderApi {
  export interface orderParams {
    orderNo?: string;
    name: string;
    price: number | null;
  }
  export interface listItem {
    createTime: string;
    id: string;
    orderNo?: string;
    name: string;
    price: number;
    state: number;
    priceDateTimeRangeVOList: {
      endTime: string;
      id: string;
      price: number;
      startTime: string;
      state: number;
    }[];
  }
  export interface getOrderListResult {
    code: number;
    message: string;
    data: {
      total: string;
      list: listItem[];
    };
  }
  export interface getDetailResult {
    code: number;
    message: string;
    data: listItem;
  }
}

/**
 * 获取商品列表
 */
export async function getOrderList(params: {
  orderNo?: string;
  state?: number;
  pageNum: number;
  pageSize: number;
}) {
  return requestClient.get<orderApi.getOrderListResult>(
    '/basic/order/getOrderPage',
    { params },
  );
}

/**
 * 根据ID获取订单详情
 */
export async function getOrderDetails(orderNo: string) {
  return requestClient.get<orderApi.getDetailResult>(
    `/basic/order/getOrderDetails`,
    { params: { orderNo } },
  );
}
// 订单退款
export async function refundOrder(apptProductId: string) {
  return requestClient.post(
    `/basic/order/adminOrderRefund
`,
    { apptProductId },
  );
}
// 订单退款记录列表

export async function getRefundRecordList(params: {
  orderNo?: string;
  pageNum: number;
  pageSize: number;
  refundOrderNo?: string;
}) {
  return requestClient.get<orderApi.getOrderListResult>(
    '/basic/orderRefundLog/getOrderRefundLogPage',
    { params },
  );
}
// 订单核销记录列表
export async function getWriteoffRecordList(params: {
  orderNo?: string;
  pageNum: number;
  pageSize: number;
}) {
  return requestClient.get<orderApi.getOrderListResult>(
    '/basic/orderRefundLog/getOrderRedemptionLogPage',
    { params },
  );
}
